{% extends 'base.html' %}
{% load humanize %}
{% block page-content %}
{% include 'nav_cat_bar.html' %}
{# load mytags  #}

<link href="/static/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.responsive.css" rel="stylesheet">
<link href="/static/css/plugins/dataTables/dataTables.tableTools.min.css" rel="stylesheet">

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据库初始化</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="#">未启用 1</a>
                            </li>
                            <li><a href="#">未启用 2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>

                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-12 m-b-xs">
                            {% for pro in pro_info %}
                                <a type="button" class="btn btn-primary btn-sm" href="{% url 'asset_status' %}?project={{pro.mini_name}}">{{pro.name}}</a>
                            {% endfor %}
                        </div>
                    </div>
                    <form id="contents_form" name="contents_form">
                    <table class="table table-striped table-bordered table-hover dataTables-example" >
                        <thead>
                            <tr>
                                <th class="text-center">编号</th>
                                <th class="text-center">项目名称</th>
                                <th class="text-center">机房</th>
                                <th class="text-center">服务器类型</th>
                                <th class="text-center">公网地址</th>
                                <th class="text-center">端口</th>
                                <th class="text-center">备注</th>
                                <th class="text-center">资产状态</th>
                            </tr>
                        </thead>
                        <tbody>
                        {% for num in host_info %}
                          <tr class="text-center">
                            <td>
                            {% ifequal num.asset_status 1%}
                                {{forloop.counter}}.<input type="checkbox" data-toggle="checkbox" name="nochoice" DISABLED>
                            {% else %}
                                {{forloop.counter}}.<input type="checkbox" data-toggle="checkbox" name="choice_host" value="{{ num.p_ip }}">
                            {% endifequal %}
                            </td>
                            <td>{{num.project.mini_name}}</td>
                            <td>{{num.idc}}</td>
                            <td>{{num.os_type}}</td>
                            <td>{{num.p_ip}}</td>
                            <td>{{num.port}}</td>
                            <td>{{num.commit}}</td>
                            <td>
                              {% ifequal num.asset_status 1 %}
                                <font color="green">已采集</font>
                              {% else %}
                                <font color="red">未采集</font>
                              {% endifequal %}
                            </td>
                          </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    <!--<input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')">全选/全不选 -->
                    <input type="radio" data-toggle="radio"  name="checkradio" id="SelectAll" data-radiocheck-toggle="radio" onclick="choice(valu='all')" >全选
                    <input type="radio" data-toggle="radio" name="checkradio" id="SelectAll"  data-radiocheck-toggle="radio" onclick="choice(valu='no')">反选
                    </form>
                    </br>
                    <button type="submit" class="btn btn-success dim" name="switch" form="contents_form" formmethod="post" formaction="{% url 'asset_update' %}?project={{ project }}">采集资产信息</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/static/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.responsive.js"></script>
<script src="/static/js/plugins/dataTables/dataTables.tableTools.min.js"></script>
<script type="text/javascript">
    function choice(valu){
                var ids=$("input[name='choice_host']");
                if (valu == "all"){
　　                    for(var i=0;i<ids.length;i++){
　　　　                        ids[i].checked="checked";
　　                    }
                }else if (valu == "no") {
　　                    for(var i=0;i<ids.length;i++){
　　　　                ids[i].checked="";
　　                    }
                }
        };

    $(document).ready(function() {
            $('.dataTables-example').dataTable({
                responsive: true,
                "dom": 'T<"clear">lfrtip',
                "iDisplayLength":50,
                "tableTools": {
                    "aButtons":["copy","xls",'print'],
                    "sSwfPath": "/static/js/plugins/dataTables/swf/copy_csv_xls_pdf.swf"
                }
            });
        });
</script>

{% endblock %}
